/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package smary.ejb.entity;

import java.io.Serializable;
import java.util.Set;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * Entität zur Speicherung der Benutzerkonten, als Login wird die Email
 * verwendet indes darf diese auch nur einmalig vorkommen.
 * 
 * Die Beziehungen sind
 *      1 zu N Capacities Entität
 *      N zu 1 Rollen Entität
 *      N zu 1 Scrumteam Entität
 *      1 zu N Tasks Entität
 *      1 zu N Tippdestages Entität
 * @author Alexander Cannell
 */
@Entity
@Table(name = "USERLOGINACCOUNT")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Userloginaccount.findAll", query = "SELECT u FROM Userloginaccount u"),
    @NamedQuery(name = "Userloginaccount.findByLoginid", query = "SELECT u FROM Userloginaccount u WHERE u.loginid = :loginid"),
    @NamedQuery(name = "Userloginaccount.findByVorname", query = "SELECT u FROM Userloginaccount u WHERE u.vorname = :vorname"),
    @NamedQuery(name = "Userloginaccount.findByNachname", query = "SELECT u FROM Userloginaccount u WHERE u.nachname = :nachname"),
    @NamedQuery(name = "Userloginaccount.findByEmail", query = "SELECT u FROM Userloginaccount u WHERE u.email = :email"),
    @NamedQuery(name = "Userloginaccount.findByPasswort", query = "SELECT u FROM Userloginaccount u WHERE u.passwort = :passwort"),
    @NamedQuery(name = "Userloginaccount.findByScrumteam", query = "SELECT u FROM Userloginaccount u WHERE u.scrumteam = :scrumteam")})
public class Userloginaccount implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "LOGINID")
    @GeneratedValue(strategy= GenerationType.AUTO)
    private Integer loginid;
    @Size(max = 128)
    @Column(name = "VORNAME")
    private String vorname;
    @Size(max = 128)
    @Column(name = "NACHNAME")
    private String nachname;
    // @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Ungültige E-Mail")//if the field contains email address consider using this annotation to enforce field validation
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 256)
    @Column(name = "EMAIL")
    private String email;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 512)
    @Column(name = "PASSWORT")
    private String passwort;
//    @Column(name = "ROLLENID")
//    private Short rollenid;
//    @Column(name = "SCRUMTEAMID")
//    private Integer scrumteamid;

    @ManyToOne
    @JoinColumn(name="SCRUMTEAMID",referencedColumnName="SCRUMTEAMID")
    protected Scrumteam scrumteam;
    
    @ManyToOne
    @JoinColumn(name="USER_ROLLENID",referencedColumnName="ROLLENID")
    protected Rollen rolle;
    
    @OneToMany(mappedBy="tdtauthor")
    protected Set<Tippdestages> tdt;
    
    @OneToMany(mappedBy="user")
    protected Set<Capacity> capacities;
    
    @ManyToMany(mappedBy="users")
    protected Set<Task> tasks;

    public Set<Task> getTasks() {
        return tasks;
    }

    public void setTasks(Set<Task> tasks) {
        this.tasks = tasks;
    }

    public Set<Capacity> getCapacities() {
        return capacities;
    }

    public void setCapacities(Set<Capacity> capacities) {
        this.capacities = capacities;
    }

    public Set<Tippdestages> getTdt() {
        return tdt;
    }

    public void setTdt(Set<Tippdestages> tdt) {
        this.tdt = tdt;
    }


    public Rollen getRolle() {
        return rolle;
    }

    public void setRolle(Rollen rolle) {
        this.rolle = rolle;
    }

    public Scrumteam getScrumteam() {
        return scrumteam;
    }

    public void setScrumteam(Scrumteam scrumteam) {
        this.scrumteam = scrumteam;
    }
    
    public Userloginaccount() {
        this.email = "";
        this.passwort = "";
    }

    public Userloginaccount(Integer loginid) {
        this.loginid = loginid;
    }

    public Userloginaccount(Integer loginid, String email, String passwort) {
        this.loginid = loginid;
        this.email = email;
        this.passwort = passwort;
    }

    public Integer getLoginid() {
        return loginid;
    }

    public void setLoginid(Integer loginid) {
        this.loginid = loginid;
    }

    public String getVorname() {
        return vorname;
    }

    public void setVorname(String vorname) {
        this.vorname = vorname;
    }

    public String getNachname() {
        return nachname;
    }

    public void setNachname(String nachname) {
        this.nachname = nachname;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPasswort() {
        return passwort;
    }

    public void setPasswort(String passwort) {
        this.passwort = passwort;
    }
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (loginid != null ? loginid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Userloginaccount)) {
            return false;
        }
        Userloginaccount other = (Userloginaccount) object;
        if ((this.loginid == null && other.loginid != null) || (this.loginid != null && !this.loginid.equals(other.loginid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return getLoginid() + " " + getEmail();
    }
    
}
